#import <Cocoa/Cocoa.h>
#import "ALElementBarGlobals.h"


-(void)windowChangedKey:(NSNotification *)note {
	[self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
}

-(void)viewDidMoveToWindow {
	[super viewDidMoveToWindow];
	NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
	if ([self window])
		[noteCenter addObserver:self selector:@selector(windowChangedKey:) name:NSWindowDidResignKeyNotification object:[self window]];
	else 
		[noteCenter removeObserver:self name:NSWindowDidResignKeyNotification object:nil];
}

-(BOOL)becomeFirstResponder {
	[[self superview] sortSubviewsUsingFunction:&elementBarCompareMeOnTop context:self];
	BOOL willChange = [super becomeFirstResponder];
	if (willChange)
		[self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
	return willChange;
}

-(BOOL)resignFirstResponder {
	BOOL willChange = [super resignFirstResponder];
	if (willChange)
		[self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
	return willChange;
}
